<template>
  <div>
    ip:<Input v-model="url" /> 端口:<Input v-model="port" />
    <Button @click="testConnect">链接测试</Button>
    文件路径:<Input v-model="file" />
    <Button @click="getFile">读取文件</Button>
    文件代码:<Input v-model="code" />
      <Radio v-model="codeType" true-value="equipment">装备</Radio>
      <Radio v-model="codeType" true-value="stackable">道具</Radio>
    {{codeType}}
    <Button @click="getFileByCode">读取文件</Button>
    <div v-html="data"></div>
  </div>
</template>

<script>
export default {
  name: 'dictionary',
  data() {
    return {
      url: '127.0.0.1',
      port: '2020',
      data: '',
      file: '',
      code: '',
      codeType: 'equipment'
    }
  },
  created() {
    this.testConnect()
  },
  mounted() {},
  methods: {
    testConnect() {
      const url = this.url
      const port = this.port
      const postData = {
        Cmd: 0,
        Value: 'stackable/gold.stk',
        UseDecompile: '1'
      }
      this.getFile(url, port, postData).then((res) => {
        this.data = res
      })
    },
    getFileByCode() {
      let temp = []
      const url = this.url
      const port = this.port
      const codeType = this.codeType
      if(this.codeType === 'equipment'){
        if(this.code === '') {
          this.$Message.error({ content: '请输入装备代码' })
          return
        }
        const postData = {
          Cmd: 0,
          Value: 'equipment/equipment.lst',
          UseDecompile: '0'
        }
        this.getFile(url, port, postData).then((res) => {
          let arr = res.split('<br/>')
          arr.forEach((i) => {
            if(i.indexOf(this.code) !== -1){
              // console.log(i.split('\t'));
              if(i.split('\t')[0] === this.code) {
                temp = i.split('\t')
              }
            }
          })
          if(temp.length === 0){
            this.$Message.error({ content: '没有找到对应的装备代码' })
          } else {
            const postData = {
              Cmd: 0,
              Value: 'equipment/' + temp[1].replaceAll(/`*/g, ''),
              UseDecompile: '1'
            }
            this.getFile(url, port, postData).then((res) => {
              this.data = res
            })
            this.$Message.success({ content: '查询成功！' })
          }
        })
      } else {
        if(this.code === '') {
          this.$Message.error({ content: '请输入道具代码' })
          return
        }
        const postData = {
          Cmd: 0,
          Value: 'stackable/stackable.lst',
          UseDecompile: '0'
        }
        this.getFile(url, port, postData).then((res) => {
          let arr = res.split('<br/>')
          arr.forEach((i) => {
            if(i.indexOf(this.code) !== -1){
              if(i.split('\t')[0] === this.code) {
                temp = i.split('\t')
              }
            }
          })
          if(temp.length === 0){
            this.$Message.error({ content: '没有找到对应的道具代码' })
          } else {
            const postData = {
              Cmd: 0,
              Value: 'stackable/' + temp[1].replaceAll(/`*/g, ''),
              UseDecompile: '1'
            }
            this.getFile(url, port, postData).then((res) => {
              this.data = res
            })
            this.$Message.success({ content: '查询成功！' })
          }
        })
      }
    },
  }
}
</script>

<style scoped></style>
